using System.Data;
using Book_Shop.DAL.DAO;

namespace Book_Shop.DAL.Gateway
{
    public class OrderDetailsGateway:DbGateway
    {
        public void Insert(OrderSheet orderSheet)
        {
            string query = "INSERT INTO OrderDetails VALUES(@bookId,@orderId,@bookQty)";
            Command.CommandText = query;
            Connection.Open();
            foreach (var book in orderSheet.Books)
            {
                Command.Parameters.Clear();
                Command.Parameters.Add("@bookId", SqlDbType.Int);
                Command.Parameters["@bookId"].Value = book.Id;
                Command.Parameters.Add("@orderId", SqlDbType.Int);
                Command.Parameters["@orderId"].Value = orderSheet.Id;
                Command.Parameters.Add("@bookQty", SqlDbType.Int);
                Command.Parameters["@bookQty"].Value = book.Qty;
                Command.ExecuteNonQuery();
            }
            Connection.Close();
            
        }
    }
}